package horncomb.bpm.persistent;

import java.util.List;

import org.springframework.dao.DataAccessException;

import com.googlecode.horncomb.bean.filter.SimpleMapConditionSet;
import com.googlecode.horncomb.orm.ibatis.SqlMapEntityDaoImpl;

import horncomb.bpm.process.core.ProcessInstance;
import horncomb.bpm.process.core.Token;

/**
 * DefaultProcessInstanceEntity data access object
 * <p>
 * 负责人/principal:<br/>
 * 修改记录/revision:<br/>
 * 日期:<br/>
 * 修改人:<br/>
 * 修改说明:<br/>
 * @author
 * @version $Id$
 */
public class DefaultProcessInstanceDao extends
		SqlMapEntityDaoImpl<ProcessInstance> {
	private static final long serialVersionUID = 8785093785562160195L;

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void initDao() throws Exception {
		this.setNamespace(Token.class.getName());
		super.initDao();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void insert(ProcessInstance entity) throws DataAccessException {
		this.insert(entity.getEntity(), null);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void update(ProcessInstance entity) throws DataAccessException {
		this.update(entity.getEntity(), null);
	}

	/**
	 * @param procInstId
	 * @return
	 */
	public int countNestedProcessInstance(String procInstId) {
		return this.queryCount(new SimpleMapConditionSet().addConstraint(
				"parentId", procInstId));
	}

	/**
	 * @param procInstId
	 * @return
	 */
	public List<? extends ProcessInstance> queryNestedProcessInstance(
			String procInstId) {
		return this.query(new SimpleMapConditionSet().addConstraint("parentId",
				procInstId), null);
	}

	/**
	 * @param procIds
	 * @return
	 */
	public List<? extends ProcessInstance> queryProcessInstanceByIds(
			String[] procIds) {
		return this.query(new SimpleMapConditionSet().addConstraint("ids",
				procIds), null);
	}
}
